﻿using NLog;
using System;
using System.IO;

namespace Ledict.ConditionExtract.Common
{
    /// <summary>
    /// 日志对象
    /// </summary>
    public  class Loger
    {
        /// <summary>
        /// 特殊日志对象应该只用于main函数中
        /// </summary>
        public static Loger GetLogger { get; set; } = new Loger();
        private readonly NLog.Logger logger;
        /// <summary>
        /// 日志的基础路径
        /// </summary>
        public string LogPath { get; set; }
        /// <summary>
        /// 日志对象
        /// </summary>
        public  Loger()
        {
            LogPath = "D:\\LedLog";
            //Path.Combine(System.Windows.Forms.Application.StartupPath, "log");
            logger = LogManager.GetCurrentClassLogger();
        }

        /// <summary>
        /// 案件日志（联调日志）
        /// </summary>
        /// <param name=" message">日志信息</param>
        /// <param name="sOutRelatID">会生成该值对应的日志路径</param>
        public  void Info(string message)
        {
            LogEventInfo logEventInfo = new LogEventInfo();

            logEventInfo.Level = LogLevel.Info;
            logEventInfo.Properties["LogPath"] = LogPath;
            logEventInfo.Message = message;
            logger.Log(logEventInfo);
        }

        /// <summary>
        /// 普通错误日志
        /// </summary>
        /// <param name="message">自定义错误信息</param>
        /// <param name="sOutRelatID">案件ID</param>
        public  void Error(string message)
        {
            LogEventInfo logEventInfo = new LogEventInfo();
            logEventInfo.Level = LogLevel.Error;
            logEventInfo.Properties["LogPath"] = LogPath;
            logEventInfo.Message = message;
            logger.Log(logEventInfo);
        }

    }
}
